home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9138 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: What does this "const" mean?
  5. Date: 28 Feb 1996 22:07:52 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4h2jno$nek@clarknet.clark.net>
  8. References: <4h0j7u$htp@crcnis3.unl.edu>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. Chi-Jang Huang (chijang@cse.unl.edu) wrote:
  16. : Hi,
  17. :      I have some problems regarding this program segment:
  18. :          class intset {
  19. :              // ...
  20. :              void start(int& i) const   { i = 0; }
  21. :              int ok(int& i) const       { return i<cursize; }
  22. :              int next(int& i) const     { return x[i++]; }
  23. :          };
  24.  
  25. Each non-static member function has an implied parameter, "this".  More 
  26. fully stated, for your class the implied parameter is 
  27.  
  28.     intset *this
  29.  
  30. The "const" after the parameter list modifies this parameter, which is 
  31. then understood to be
  32.  
  33.     const intset *this
  34.  
  35. which, as with any function parameter, tells the compiler that the 
  36. function is meant to be callable even if the argument provided is 
  37. constant, which means the compiler has to check the function to make sure 
  38. it in fact doesn't modify the argument. Nonstatic member functions that 
  39. don't have this implied const cannot be called for objects of the class 
  40. that were declared as const.
  41.  
  42.